<html>
<head><meta charset="utf-8"><title>Extend::extend · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Extend.3A.3Aextend.html">Extend::extend</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="186010213"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Extend%3A%3Aextend/near/186010213" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Extend.3A.3Aextend.html#186010213">(Jan 18 2020 at 20:16)</a>:</h4>
<p>What should a collection do if someone tries to extend it beyond it's capacity and it cannot grow the capacity?</p>
<p>major options seem to be:</p>
<p>1) Panic<br>
2) Drop the rest of the iterator items</p>
<p>This doesn't have to get added to the official docs, I'd just like to know general opinion at the moment.</p>



<a name="186010838"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Extend%3A%3Aextend/near/186010838" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Extend.3A.3Aextend.html#186010838">(Jan 18 2020 at 20:35)</a>:</h4>
<p>ArrayVec simply drops the rest of the iterator.</p>



<a name="186010841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Extend%3A%3Aextend/near/186010841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Extend.3A.3Aextend.html#186010841">(Jan 18 2020 at 20:35)</a>:</h4>
<p>I think this does need to go into the official docs for the <code>Extend</code> trait.</p>



<a name="186012918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Extend%3A%3Aextend/near/186012918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Extend.3A.3Aextend.html#186012918">(Jan 18 2020 at 21:41)</a>:</h4>
<p>I had been leaning towards "panic" for my own ArrayVec type in the <code>tinyvec</code> crate. That is what it currently does.</p>
<p>It felt consistent to panic because all the <em>other</em> ways to add elements will cause a panic on overflow.</p>



<a name="186015986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Extend%3A%3Aextend/near/186015986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Extend.3A.3Aextend.html#186015986">(Jan 18 2020 at 23:17)</a>:</h4>
<p>Panicking seems like a better option to me as well</p>



<a name="186021103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Extend%3A%3Aextend/near/186021103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Extend.3A.3Aextend.html#186021103">(Jan 19 2020 at 02:12)</a>:</h4>
<p>Dropping the rest of the elements seems <em>highly</em> unexpected</p>



<a name="186097929"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Extend%3A%3Aextend/near/186097929" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Extend.3A.3Aextend.html#186097929">(Jan 20 2020 at 12:38)</a>:</h4>
<p>The program will silently continue until you get a logic error sometime later :/</p>



<a name="186098001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Extend%3A%3Aextend/near/186098001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Extend.3A.3Aextend.html#186098001">(Jan 20 2020 at 12:40)</a>:</h4>
<p>If someone needs this to be fallible, then we can always add a <code>TryExtend</code> API, similar to how <code>try_push</code>/<code>try_reserve</code> work</p>



<a name="186124203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Extend%3A%3Aextend/near/186124203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Extend.3A.3Aextend.html#186124203">(Jan 20 2020 at 18:29)</a>:</h4>
<p><code>arrayvec</code> has <code>try_extend_from_slice</code>. It could have a an iterator-based <code>try_extend</code> method even if there’s no <code>TryExtend</code> trait in the standard library.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>